﻿using System;
using System.Web.Mvc;
using Castle.Core.Logging;
using MvcExample.Models;

namespace MvcExample.Controllers
{
	public class EmployeeController : Controller
	{
		public EmployeeController(ILogger logger)
		{
			this.Logger = logger;
		}

		public ILogger Logger { get; set; }

		public ActionResult Index()
		{
			return this.View();
		}

		public ActionResult List()
		{
			return 
				this.
					View(
						new[]
						{
							new DetailsEmployeeViewModel(),
							new DetailsEmployeeViewModel(),
							new DetailsEmployeeViewModel()
						}
					);
		}

		public ActionResult Details(int id)
		{
			return
				this.
					View(
						new DetailsEmployeeViewModel()
						{
							ID = id,
							FirstName = "James",
							MiddleName = "Jefferson",
							LastName = "Smith"
						}
					);
		}

		public ActionResult Create()
		{
			return
				this.
					View(
						new CreateEmployeeViewModel()
					);
		}

		[HttpPost()]
		public ActionResult Create(CreateEmployeeViewModel model)
		{
			if (!this.ModelState.IsValid)
			{
				return this.View(model);
			}

			return this.RedirectToAction("List");
		}

		public ActionResult Edit(int id)
		{
			return
				this.
					View(
						new EditEmployeeViewModel()
						{
							ID = id,
							FirstName = "James",
							MiddleName = "Jefferson",
							LastName = "Jones"
						}
					);
		}

		[HttpPost()]
		public ActionResult Edit(EditEmployeeViewModel model)
		{
			return this.RedirectToAction("List");
		}
	}
}